package com.avic.rong.search.adapter.searchResultFragmentsAdapters;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.avic.rong.R;

import java.util.List;

/**
 * Created by Chenjiaxin on 2019/7/20 10:58
 * E-Mail Address：16601203965@163.com
 */
public class SearchGoodsRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private LayoutInflater inflater;
    private List<String> list;
    private static final int Item1 = 0;
    private static final int Item2 = 1;
    private static int currentType = 0;

    public SearchGoodsRvAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getItemViewType(int position) {
        if (list.get(position).equals("1")) {
            currentType = Item1;
        } else {
            currentType = Item2;
        }
        return currentType;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view1 = inflater.inflate(R.layout.search_result_goods_item1, viewGroup, false);
        View view2 = inflater.inflate(R.layout.search_result_goods_item2, viewGroup, false);
        if (getItemViewType(i) == Item1)
            return new SearchGoodsRvViewHolder1(view1);
        else
            return new SearchGoodsRvViewHolder2(view2);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        if (getItemViewType(i) == Item1){
            SearchGoodsRvViewHolder1 holder = (SearchGoodsRvViewHolder1) viewHolder;

        }else {
            SearchGoodsRvViewHolder2 holder = (SearchGoodsRvViewHolder2) viewHolder;
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class SearchGoodsRvViewHolder1 extends RecyclerView.ViewHolder {

        public SearchGoodsRvViewHolder1(@NonNull View itemView) {
            super(itemView);
        }
    }

    class SearchGoodsRvViewHolder2 extends RecyclerView.ViewHolder {

        public SearchGoodsRvViewHolder2(@NonNull View itemView) {
            super(itemView);
        }
    }
}
